package com.woniuxy.microaftersaleserver.reviewmag.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.microaftersaleserver.reviewmag.service.IReviewService;
import com.woniuxy.microcommonserver.bean.aftersales_cyx.ConsultGoods;
import com.woniuxy.microcommonserver.bean.aftersales_cyx.ReviewGoods;
import com.woniuxy.microcommonserver.pageHelper.PageRequest;
import com.woniuxy.microcommonserver.pageHelper.TableResult;
import com.woniuxy.microcommonserver.res.ResultMsg;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/review")
public class ReviewServiceController {

    @Resource
    private IReviewService reviewServiceImpl;
    
    @PostMapping(value = "/add",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg addReview(ReviewGoods reviewGoods){
        reviewServiceImpl.addReviewService(reviewGoods);
        return new ResultMsg(200,"添加成功",null);
    }

    @DeleteMapping(value = "/deleted",produces =MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg deletedReview(int id){
        reviewServiceImpl.deleteReviewService(id);
        return new ResultMsg(200,"删除成功",null);
    }

    @GetMapping(value = "/select",produces = MediaType.APPLICATION_JSON_VALUE)
    public TableResult<ReviewGoods> findByParamAndPage(PageRequest request,ReviewGoods reviewGoods){
        PageInfo<ReviewGoods> pageInfo=reviewServiceImpl.findByParams(request,reviewGoods);
        System.out.println(pageInfo);
        return  new TableResult<>(pageInfo.getTotal(),pageInfo.getList());
    }

    @PutMapping(value = "/update",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg updateReview(ReviewGoods reviewGoods){
        reviewServiceImpl.updateReviewService(reviewGoods);
        return new ResultMsg(200,"修改成功",null);
    }

}
